package com.we823.project.repository.dao.product;

import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.we823.project.common.web.status.TaskStatus;
import com.we823.project.model.product.PlanDetailModel;

@Repository("planDetailRepository")
public interface PlanDetailRepository extends JpaRepository<PlanDetailModel, Integer> {

	List<PlanDetailModel> findByPlanId(Integer planId);

	Page<PlanDetailModel> findByPlanId(Integer id, Pageable pageable);

	List<PlanDetailModel> findByStatusAndStationIdIn(TaskStatus status, List<Integer> stationIds);

	@Query("select p from PlanDetailModel p where year(p.createDate)=?1")
	Page<PlanDetailModel> findByCreateDate(int year, Pageable pageable);

	@Query("select p from PlanDetailModel p where year(p.createDate)=?1 and month(p.createDate)=?2")
	Page<PlanDetailModel> findByCreateDate(int year, int month, Pageable pageable);

	@Query("select p from PlanDetailModel p where year(p.createDate)=?1 and month(p.createDate)=?2 and day(p.createDate)=?3")
	Page<PlanDetailModel> findByCreateDate(int year, int month, int day, Pageable pageable);

	@Query("select p from PlanDetailModel p where year(p.createDate)=?1")
	List<PlanDetailModel> findByCreateDate(int year);

	@Query("select p from PlanDetailModel p where year(p.createDate)=?1 and month(p.createDate)=?2")
	List<PlanDetailModel> findByCreateDate(int year, int month);

	@Query("select p from PlanDetailModel p where year(p.createDate)=?1 and month(p.createDate)=?2 and day(p.createDate)=?3")
	List<PlanDetailModel> findByCreateDate(int year, int month, int day);

	List<PlanDetailModel> findByPlanIdAndDeepAndProcessIn(int planId, int deep,
			List<String> preProcessList);

	List<PlanDetailModel> findByPlanIdAndDeepAndProcessInAndOrderidLessThan(
			int planId, int deep, List<String> preProcessList, int orderid);

	Page<PlanDetailModel> findByStationId(int stationId, Pageable pageable);

	Page<PlanDetailModel> findByIdIn(List<Integer> planDetailIdList,
			Pageable pageable);
	@Query("select p from PlanDetailModel p where year(p.createDate)=?1 and p.stationId=?2")
	Page<PlanDetailModel> findByCreateDateAndStationId(int year, int stationId,
			Pageable pageable);

	@Query("select p from PlanDetailModel p where year(p.createDate)=?1 and month(p.createDate)=?2 and p.stationId=?3")
	Page<PlanDetailModel> findByCreateDateAndStationId(int year, int month,
			int stationId, Pageable pageable);

	@Query("select p from PlanDetailModel p where year(p.createDate)=?1 and month(p.createDate)=?2 and day(p.createDate)=?3 and p.stationId=?4")
	Page<PlanDetailModel> findByCreateDateAndStationId(int year, int month,
			int day, int stationId, Pageable pageable);

	List<PlanDetailModel> findByStationId(int stationId);

	List<PlanDetailModel> findByIdIn(List<Integer> planDetailIdList);

	@Query("select p from PlanDetailModel p where year(p.createDate)=?1 and p.stationId=?2")
	List<PlanDetailModel> findByCreateDateAndStationId(int year, int stationId);
	
	@Query("select p from PlanDetailModel p where year(p.createDate)=?1 and month(p.createDate)=?2 and p.stationId=?3")
	List<PlanDetailModel> findByCreateDateAndStationId(int year, int month,
			int stationId);

	@Query("select p from PlanDetailModel p where year(p.createDate)=?1 and month(p.createDate)=?2 and day(p.createDate)=?3 and p.stationId=?4")
	List<PlanDetailModel> findByCreateDateAndStationId(int year, int month,
			int day, int stationId);

	List<PlanDetailModel> findByIdInAndStationId(
			List<Integer> planDetailIdList, int stationId);

	Page<PlanDetailModel> findByIdInAndStationId(
			List<Integer> planDetailIdList, int stationId, Pageable pageable);

	List<PlanDetailModel> findByPlanIdAndNextProcess(Integer planId,
			String nextProcess);

	Page<PlanDetailModel> findByCreateDateBetween(Date fromDate, Date endDate,
			Pageable pageable);

	List<PlanDetailModel> findByCreateDateBetween(Date fromDate, Date endDate);

	List<PlanDetailModel> findByCreateDateBetweenAndStationId(Date fromDate,
			Date endDate, int stationId);

	Page<PlanDetailModel> findByCreateDateBetweenAndStationId(Date fromDate,
			Date endDate, int stationId, Pageable pageable);
}
